package com.api.service.v1;
/**
 * 终端房间号录入
 */

import com.admin.entity.Station;
import com.admin.entity.Terminal;
import com.admin.enums.StationType;
import com.admin.enums.TerminalLineType;
import com.admin.enums.TerminalLockType;
import com.admin.mapper.TerminalMapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.Map;

@SuppressWarnings("ALL")
@Service
public class LoginApiService {
    @Autowired
    private TerminalMapper terminalMapper;

    public Map getRoomAndId(Station s, Terminal t) {
        Map map = new HashMap();
        return map;
    }

    /**
     * 统计站点终端总数
     * @param stationId
     * @return
     */
    public int countTerminal(Integer stationId) {
        QueryWrapper q = new QueryWrapper();
        q.eq("terminal_station",stationId);
        int count = terminalMapper.selectCount(q);
        return count;
    }

    /**
     * 统计站点下某个房间号个数
     * @param stationId  站点编号
     * @param room 房间号
     * @return
     */
    public int countRoom(Integer stationId, String room) {
        QueryWrapper q = new QueryWrapper();
        q.eq("terminal_station",stationId);
        q.eq("terminal_room",room);
        int count = terminalMapper.selectCount(q);
        return count;
    }

    /**
     * 新增终端
     * @param station  站点
     * @param  room  房间号
     * @param mac       mac
     * @param ip
     * @param systemModel  类型
     * @param versionCode  版本
     */
    public void registTerminal(Station station, String room,String mac, String ip, String systemModel, String versionCode) {
        Terminal t = new Terminal();
        t.setTerminalStation(station.getStationId());
        t.setTerminalLine(TerminalLineType.离线.name());
        t.setTerminalIp(ip);
        if (StationType.买断.name().equals( station.getStationModel()))
        {
            t.setTerminalLock(TerminalLockType.正常.name());
        }else
        {
            t.setTerminalLock(TerminalLockType.已锁定.name());
        }
        t.setTerminalMac(mac);
        t.setTerminalRoom(room);
        t.setTerminalSystemModel(systemModel);
//        t.setTerminalTotalOnlineTime(0);
        t.setTerminalVersionCode(versionCode);
        terminalMapper.insert(t);
    }
}
